package  
{
	import org.flixel.*;
	
	/**
	 * ...
	 * @author JAC
	 */
	public class Light extends FlxSprite
	{
		private var _parent:FlxObject;
		private var _parentOffset:FlxPoint;
		
		public function Light(i:uint = 0, j:uint = 0, parent:FlxObject = null) 
		{
			i = i * Maze.tileWidth;
			j = j * Maze.tileHeight;
			
			super(i, j);
			
			if (parent != null)
			{
				x = parent.x;
				y = parent.y;
			}
			
			_parent = parent;
			_parentOffset = new FlxPoint(0, 0);
			
			loadGraphic(Assets.ImgLight);
			
			width = Maze.tileWidth;
			height = Maze.tileHeight;
			centerOffsets();
			
			blend = "screen";
			
			Registry.lights.add(this);
		}
		
		override public function update():void
		{
			if (_parent != null)
			{
				x = _parent.x;
				y = _parent.y;
			}
		}
		
		override public function draw():void
		{
			Registry.darkness.stamp(this, x - FlxU.abs(offset.x) + _parentOffset.x, y - FlxU.abs(offset.y) + _parentOffset.y);
		}
		
		public function setParentOffset(offsetX:int, offsetY:int):void
		{
			_parentOffset.make(offsetX, offsetY);
		}
	}

}